/************************************************************************/
/*               (C) Fujitsu Semiconductor Europe GmbH                  */
/*                                                                      */
/* The following software deliverable is intended for and must only be  */
/* used for reference and in an eMASKuation laboratory environment.      */
/* It is provided on an as-is basis without charge and is subject to    */
/* alterations.                                                         */
/* It is the user?s obligation to fully test the software in its        */
/* environment and to ensure proper functionality, qualification and    */
/* compliance with component specifications.                            */
/*                                                                      */
/* In the event the software deliverable includes the use of open       */
/* source components, the provisions of the governing open source       */
/* license agreement shall apply with respect to such software          */
/* deliverable.                                                         */
/* FSEU does not warrant that the deliverables do not infringe any      */
/* third party intellectual property right (IPR). In the event that     */
/* the deliverables infringe a third party IPR it is the sole           */
/* responsibility of the customer to obtain necessary licenses to       */
/* continue the usage of the deliverable.                               */
/*                                                                      */
/* To the maximum extent permitted by applicable law FSEU disclaims all */
/* warranties, whether express or implied, in particular, but not       */
/* limited to, warranties of merchantability and fitness for a          */
/* particular purpose for which the deliverable is not designated.      */
/*                                                                      */
/* To the maximum extent permitted by applicable law, FSEU?s liability  */
/* is restricted to intention and gross negligence.                     */
/* FSEU is not liable for consequential damages.                        */
/*                                                                      */
/* (V1.4)                                                               */
/************************************************************************/
/** \file KEY.h
 **
 ** MCU description file
 **
 ** History:
 **   2013-11-03  1.0  Mark  First version
 *****************************************************************************/

#ifndef __KEY_H__
#define __KEY_H__
/*****************************************************************************/
/* Include files                                                             */
/*****************************************************************************/
#include "mcu.h"
#include "base_types_l3.h"
#define _BUTTON_API_MSC_
#define API_NUMBEROFBUTTONS 7
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define')                           */
/*****************************************************************************/
#define KEY1    	bFM3_GPIO_PDIR6_P2
#define KEY2    	bFM3_GPIO_PDIR6_P3
#define KEY_DOWN  	bFM3_GPIO_PDIR6_P4
#define KEY_LEFT  	bFM3_GPIO_PDIR6_P5
#define KEY_UP  	bFM3_GPIO_PDIR6_P6
#define KEY_RIGHT  	bFM3_GPIO_PDIR6_P7
#define KEY_CENTER 	bFM3_GPIO_PDIR6_P8

#define KEY_PDR     FM3_GPIO->PDIR6
#define KEY_DDR     FM3_GPIO->DDR6
#define KEY_PFR		FM3_GPIO->PFR6

#define KEY_MASK    0x01FC
#define KEY1_MASK		(1<<2)
#define KEY2_MASK		(1<<3)
#define	KEY_CENTER_MASK	(1<<8)
#define KEY_RIGHT_MASK   (1<<5)
#define KEY_DOWN_MASK    (1<<6)
#define KEY_LEFT_MASK    (1<<7)
#define KEY_UP_MASK      (1<<4)

#define KEY_PRESSED()         (KEY_PDR & KEY_MASK)
#define KEY_CENTER_PRESSED()  ((KEY_PDR & KEY_CENTER_MASK) != KEY_CENTER_MASK)
#define KEY_RIGHT_PRESSED()   ((KEY_PDR & KEY_RIGHT_MASK) != KEY_RIGHT_MASK)
#define KEY_DOWN_PRESSED()    ((KEY_PDR & KEY_DOWN_MASK) != KEY_DOWN_MASK)
#define KEY_LEFT_PRESSED()    ((KEY_PDR & KEY_LEFT_MASK) != KEY_LEFT_MASK)
#define KEY_UP_PRESSED()      ((KEY_PDR & KEY_UP_MASK) != KEY_UP_MASK)

#define BUTTON_CENTER_PRESSED()	KEY_CENTER_PRESSED()
#define BUTTON_RIGHT_PRESSED()	KEY_RIGHT_PRESSED()
#define BUTTON_DOWN_PRESSED()	KEY_DOWN_PRESSED()
#define BUTTON_LEFT_PRESSED()	KEY_LEFT_PRESSED()
#define BUTTON_UP_PRESSED()		KEY_UP_PRESSED()
/*****************************************************************************/
/* Global type definitions ('typedef')                                       */
/*****************************************************************************/

/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source)           */
/*****************************************************************************/

/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source)             */
/*****************************************************************************/

void KEY_Init(void);

#endif /* __MCU_H__ */
